//Varga David,522, vdim1182 Labor 1
import java.awt.BorderLayout;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;


public class Server extends JFrame{

	private JPanel jPanel = new JPanel();
	private JTextArea keresekKlenstol = new JTextArea(4,30);
	private JLabel jLabel = new JLabel("Keresek a klienstol :P");
	
	public Server() {
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jPanel.setLayout(new BorderLayout());
		jPanel.add(jLabel,BorderLayout.NORTH);
		jPanel.add(keresekKlenstol,BorderLayout.CENTER);
		keresekKlenstol.setEditable(false);
		this.setContentPane(jPanel);
		this.pack();
	}
	
	public void go() {
		try {
			ServerSocket socket = new ServerSocket(9292);
			
			while (true) {
				//mikor letrehozom a socket et tulajdonkeppen az accept metodus hivodik meg es ezzel fog a ket fel komunikalni 
				Socket ss = socket.accept();
				SzerverSzal szSzal = new SzerverSzal(ss,keresekKlenstol);
				Thread th = new Thread(szSzal);
				th.start();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		Server server = new Server();
		server.setVisible(true);
		server.go();
	}

}
